package com.example.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class PortSerivce /*implements ApplicationListener<WebServerInitializedEvent>*/ {

    @Value("${server.servlet.context-path}")
    private String path;

    @Value("${server.port}")
    private int port;

//    @Override
//    public void onApplicationEvent(WebServerInitializedEvent event) {
//        try {
//            port = event.getWebServer().getPort();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    public int getPort() {
        return port;
    }

    public String getPath() {
        if(path == null || path.equals("") || path.equals("/") )
            return "";
        return path;
    }
}